<template>
  <div class="app-container">
    <div class="left-box" :style="{ height: tableHeight + 104 + 'px' }">
      <xh-area @select="handleNodeClick"></xh-area>
    </div>
    <div class="right-box">
      <xh-list-head
        @on-search="HandleChange"
        ref="TableHead"
        crmType="plantask"
        :showJob="false"
        :fielname="fielname"
        :listHander="listHander"
        :pictureExport="true"
        :defaultDateRang="defaultDateRang"
      >
        <div class="u-box">
          <span>点检结果：</span>
          <el-select v-model="result" placeholder="请选择">
            <el-option
              v-for="item in resultOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>
      </xh-list-head>
      <el-table
        v-loading="listLoading"
        :data="tableData"
        element-loading-text="加载中"
        :height="tableHeight"
        use-virtual
        stripe
        border
        highlight-current-row
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column
          show-overflow-tooltip
          type="selection"
          align="center"
          width="55"
        />
        <el-table-column label="ID" align="center" fixed="left">
          <template slot-scope="scope">
            {{ scope.row.itemid }}
          </template>
        </el-table-column>
        <el-table-column label="任务名称" align="center" fixed="left">
          <template slot-scope="scope">
            {{ scope.row.itemname }}
          </template>
        </el-table-column>
        <el-table-column
          class-name="status-col"
          label="任务状态"
          align="center"
        >
          <template slot-scope="scope">
            <el-tag :type="scope.row.itemstatus | statusFilter">{{
              scope.row.itemstatus | formatStatus
            }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          class-name="status-col"
          label="点检结果"
          align="center"
        >
          <template slot-scope="scope">
            <el-tag
              :type="(scope.row.actresult + 1) | statusFilter"
              v-if="scope.row.actresult"
              >{{ scope.row.actresult | formatState }}</el-tag
            >
          </template>
        </el-table-column>
        <el-table-column label="区域" align="center">
          <template slot-scope="scope">
            {{ scope.row.zonename }}
          </template>
        </el-table-column>
        <el-table-column label="创建人" align="center">
          <template slot-scope="scope">
            {{ scope.row.createname }}
          </template>
        </el-table-column>
        <el-table-column label="创建时间" align="center">
          <template slot-scope="scope">
            {{ scope.row.createt }}
          </template>
        </el-table-column>
        <el-table-column label="执行人" align="center">
          <template slot-scope="scope">
            {{ scope.row.exename }}
          </template>
        </el-table-column>
        <el-table-column label="周期" align="center">
          <template slot-scope="scope">
            {{ scope.row.period }}
          </template>
        </el-table-column>

        <el-table-column label="操作" width="130" fixed="right" align="center">
          <template slot-scope="scope">
            <el-button
              size="mini"
              @click="handleEdit(scope.$index, scope.row)"
              class="xm-btn--primary"
              type="primary"
              >查看</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div class="p-contianer">
        <el-pagination
          :current-page="currentPage"
          :page-sizes="pageSizes"
          :page-size.sync="pageSize"
          :total="total"
          :pager-count="5"
          class="p-bar"
          background
          layout="prev, pager, next, sizes, total, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>

    <!-- 详情 -->
    <xh-plan-task-detail
      :visible.sync="showDView"
      :id="dutyId"
      @close="showDView = false"
    />
  </div>
</template>

<script>
import XhListHead from "@/components/XhListHead/index.vue";
import { getActItemTaskAPI } from "@/api/inspection";
import { getArea } from "@/api/common";
import TableMixin from "@/views/mixins/Table";
import XhPlanTaskDetail from "./Detail.vue";
import XhArea from "@/components/XhArea";
import moment from "moment";
export default {
  mixins: [TableMixin],

  components: {
    XhListHead,
    XhPlanTaskDetail,
    XhArea,
  },
  data() {
    return {
      list: null,
      listLoading: true,

      // 默认搜索事件
      defaultDateRang: [
        moment().subtract(30, "days").calendar(),
        moment().add(1, "days"),
      ],

      // 筛选
      /**职务 */
      result: "",
      resultOptions: [
        {
          label: "全部",
          value: "",
        },
        {
          label: "正常",
          value: 1,
        },
        {
          label: "异常",
          value: 2,
        },
      ],

      //详情
      showDView: false,
      dutyId: "",

      //导出
      fielname: "计划点检",
      listHander: {
        itemname: "任务名称",
        createt: "创建时间",
        createname: "创建人",
        exename: "执行人",
        zoneid: "区域",
        itemstatus: "任务状态",
        period: "周期",
      },
    };
  },
  mounted() {
    this.$nextTick(() => {
      this.search = {
        actresult: this.result,
        ...this.$refs.TableHead.formatSearch(),
      };
      this.getList(this.search);
    });
  },
  methods: {
    /** tableData */
    getList(search) {
      this.listLoading = true;
      if (search && search.hasOwnProperty("dutystatus")) {
        search.itemstatus = search.dutystatus;
        delete search.dutystatus;
      }

      if (search && search.hasOwnProperty("executets")) {
        search.exetstart = search.executets;
        search.exetend = search.executete;
        delete search.executets;
        delete search.executete;
      }

      getActItemTaskAPI({
        pagenum: this.currentPage - 1,
        pagesize: this.pageSize,
        ...search,
      }).then((res) => {
        this.tableData = res.Data;
        this.total = res.Total;
        this.listLoading = false;
      });
    },

    /**职务 */
    HandleChange() {
      const params = {
        actresult: this.result,
        ...this.$refs.TableHead.formatSearch(),
      };
      this.handleSearch(params);
    },

    /**查看*/
    handleEdit(index, row) {
      this.showDView = true;
      this.dutyId = row.actpathid;
    },

    //tree
    handleNodeClick(data) {
      if (data.Zoneid) {
        this.search.zoneid = data.Zoneid;
      } else {
        delete this.search.zoneid;
      }

      this.getList(this.search);
    },
  },
};
</script>
<style lang="scss" scoped>
.app-container {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .left-box {
    width: 260px;
    height: 100%;
    background: #ffffff;
    margin-right: 10px;
    .tree-head {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 0 15px;
      height: 50px;
      line-height: 50px;
      border-bottom: 1px solid #eee;
      font-size: 15px;
      font-weight: bold;
      span {
        display: block;
      }
      i {
        margin-right: 10px;
        font-weight: bold;
        font-size: 15px;
      }
    }

    .tree-box {
      width: 260px;
      max-width: 260px;
      height: calc(100% - 50px);
      overflow: auto;
      padding: 15px 5px;
    }
    .el-tree {
      max-width: 100%; //200px;
      overflow: auto;
    }

    ::v-deep {
      .el-tree > .el-tree-node {
        display: inline-block;
        min-width: 100%;
      }
    }
  }
  .right-box {
    width: calc(100% - 260px);
  }

  .u-box {
    display: flex;
    align-items: center;
    // width: 25%;
    min-width: 10rem;
    span {
      min-width: 75px;
    }
  }
}
</style>
